package com.chujian.system.core.controller;

import com.chujian.framework.core.base.BaseController;
import com.chujian.framework.core.base.BaseService;
import com.chujian.framework.core.tsdata.Result;
import com.chujian.core.entity.CoreCfg;
import com.chujian.system.core.service.CoreCfgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 配置表控制层
 *
 * @author yj
 * @since 2021-07-28
 */
@RequestMapping("/coreCfg")
@RestController
@Slf4j
public class CoreCfgController extends BaseController<CoreCfg> {

    @Resource
    private CoreCfgService baseService;

    @Override
    public BaseService<CoreCfg> getBaseService() {
        return baseService;
    }

    /**
     * 保存ac级的配置
     *
     * @param acId
     * @param cfg
     * @return
     */
    @PostMapping("/saveAcConfig")
    public Result<?> saveAcConfig(@RequestParam("acId") Long acId, @RequestBody CoreCfg cfg) {
        cfg = baseService.saveAcConfig(acId, cfg);
        return okRs(cfg);
    }

    @GetMapping("/getAcConfig")
    public Result<?> getAcConfig(@RequestParam("acId") Long acId, @RequestParam("cfgKey") String cfgKey) {
        CoreCfg cfg = baseService.getOne(acId, cfgKey);
        return okRs(cfg);
    }

    @GetMapping("/getAcConfigs")
    public Result<?> getAcConfigs(@RequestParam("acId") Long acId, @RequestParam("cfgKey") String cfgKey) {
        List<CoreCfg> cfgs = baseService.list(acId, cfgKey);
        return okRs(cfgs);
    }


}
